import Vue from 'vue';
import VueRouter from 'vue-router';
// import Layout from '../components/layout/Layout';

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    component: () => import(/* webpackChunkName: "Layout" */ '../components/layout/Layout'),
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        meta: { id: 0 },
        component: () => import(/* webpackChunkName: "UserCenter" */ '../views/dashboard/Dashboard')
      },
      {
        path: 'user/user-list',
        name: 'UserList',
        meta: { id: 2 },
        component: () => import('../views/userList/UserList')
      },
      {
        path: 'menu/menu-list',
        name: 'MenuList',
        meta: { id: 3 },
        component: () => import('../views/menuList/MenuList')
      },
      {
        path: 'role/role-list',
        name: 'RoleList',
        meta: { id: 4 },
        component: () => import('../views/roleList/RoleList')
      },
      {
        path: 'test1',
        name: 'Test1',
        meta: { id: 7 },
        component: () => import('../views/test1/Test1')
      },
      {
        path: 'test2',
        name: 'Test2',
        meta: { id: 9 },
        component: () => import('../views/test2/Test2')
      },
      {
        path: 'test3',
        name: 'Test3',
        meta: { id: 10 },
        component: () => import('../views/test3/Test3')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login/Login')
  }
];

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});

// 解决vue路由重复导航错误
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location) {
  return originalPush.call(this, location).catch(err => err);
};

export default router;
